package com.li;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lirenchun
 */
public class CollectionSortUtil {
    /**
     * 字符集合升序排序
     *
     * @param list 被排序字符集合
     * @return
     */
    public static List<String> CollectionAscOrder(List<String> list) {
        list = list.stream().sorted(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 字符集合降序排序
     *
     * @param list 被排序字符集合
     * @return
     */
    public static List<String> CollectionDescOrder(List<String> list) {
        list = list.stream().sorted(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.compareTo(o1);
            }
        }).collect(Collectors.toList());
        return list;
    }

    public static void main(String[] args) {
        List<String> stringList = new ArrayList<>();
        stringList.add("shanghai");
        stringList.add("alas");
        stringList.add("zdvf");
        CollectionDescOrder(stringList).forEach(str -> System.out.println(str));
    }
}
